/**
 * 
 */
package co.fitstart.entity.coach;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;

import co.fitstart.entity.principal.Principal;
import co.fitstart.entity.site.Site;

import com.demo2do.core.utils.DateFormatUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * @author downpour
 *
 */
@Entity
@Table(name = "coach_salary")
@DynamicUpdate
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class CoachSalary {
    
    @Id
    @GeneratedValue
    private Long id;
    
    /** 上课教练 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Principal principal;
    
    /** 上课门店 */
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private Site site;
    
    /** 
     * course round code + courseTime + courseDay  
     */
    private String code;
    
    /** 发放月份 */
    private String month;
    
    /** 发放金额 */
    private int money;
    
    /** 课时数 */
    private int hour;
    
    /** 课程描述（具体课程名称） */
    private String courseDescription;
    
    /** 上课日期 */
    @Type(type = "date")
    private Date courseDay;
    
    /** 上课时间 */
    private String courseTime;
    
    /** 创建时间 */
    private Date createTime;
    
    /**
     * The default constructor
     */
    public CoachSalary() {
        
    }

    /**
     * create coach salary
     * 
     * @param code
     * @param coach
     * @param money
     */
    public CoachSalary(String code, Principal coach, int money) {
        this.code = code;
        this.principal = coach;
        this.money = money;
        this.hour = 1;
        
        this.createTime = new Date();
        this.month = DateFormatUtils.format(this.createTime, "yyyy-MM");
        
    }
    
    /**
     * 
     * @param coachSettlement
     * @param code
     * @param courseDay
     * @param courseTime
     * @param site
     */
    public CoachSalary(CoachSettlement coachSettlement, String code, Date courseDay, String courseTime, Site site) {
        
        this.principal = coachSettlement.getPrincipal();
        this.money = coachSettlement.getSettlement();
        
        this.code =code;
        this.hour = 1;
        this.courseDescription = coachSettlement.getCourse().getName();
        
        this.courseDay = courseDay;
        this.courseTime = courseTime;
        
        this.site = site;
        
    }
    
    /**
     * 
     * @return
     */
    public CoachSalary initialize() {
        this.createTime = new Date();
        this.month = DateFormatUtils.format(this.createTime, "yyyy-MM");
        return this;
    }
    
    /**
     * initialize coach salary with course information
     * 
     * @param site
     * @param courseDay
     * @param courseTime
     * @return
     */
    public CoachSalary initialize(Site site, Date courseDay, String courseTime) {
        
        this.site = site;
        
        this.courseDay = courseDay;
        this.courseTime = courseTime;
        
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the principal
     */
    public Principal getPrincipal() {
        return principal;
    }

    /**
     * @return the site
     */
    public Site getSite() {
        return site;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the month
     */
    public String getMonth() {
        return month;
    }

    /**
     * @return the money
     */
    public int getMoney() {
        return money;
    }

    /**
     * @return the hour
     */
    public int getHour() {
        return hour;
    }

    /**
     * @return the courseDescription
     */
    public String getCourseDescription() {
        return courseDescription;
    }

    /**
     * @return the courseDay
     */
    public Date getCourseDay() {
        return courseDay;
    }

    /**
     * @return the courseTime
     */
    public String getCourseTime() {
        return courseTime;
    }

    /**
     * @return the createTime
     */
    public Date getCreateTime() {
        return createTime;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param principal the principal to set
     */
    public void setPrincipal(Principal principal) {
        this.principal = principal;
    }

    /**
     * @param site the site to set
     */
    public void setSite(Site site) {
        this.site = site;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param month the month to set
     */
    public void setMonth(String month) {
        this.month = month;
    }

    /**
     * @param money the money to set
     */
    public void setMoney(int money) {
        this.money = money;
    }

    /**
     * @param hour the hour to set
     */
    public void setHour(int hour) {
        this.hour = hour;
    }

    /**
     * @param courseDescription the courseDescription to set
     */
    public void setCourseDescription(String courseDescription) {
        this.courseDescription = courseDescription;
    }

    /**
     * @param courseDay the courseDay to set
     */
    public void setCourseDay(Date courseDay) {
        this.courseDay = courseDay;
    }

    /**
     * @param courseTime the courseTime to set
     */
    public void setCourseTime(String courseTime) {
        this.courseTime = courseTime;
    }

    /**
     * @param createTime the createTime to set
     */
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}
